package com.umer.pinban.adapter.customer;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.common.ui.recycleview.PullLoadMoreRecyclerView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicPageAdapterTwo;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.DataStateListener;
import com.common.ui.recycleview.listener.OptListener;
import com.umer.pinban.R;
import com.umer.pinban.bean.customer.XiaoFeiRecordBean;
import com.umer.pinban.bean.customer.XiaoFeiRecordItemBean;
import java.util.List;

public class CustomerXiaoFeiRecordAdapter extends RecyclerviewBasicPageAdapterTwo<XiaoFeiRecordBean>
        implements OptListener {

    private OptListener optListener;

    public CustomerXiaoFeiRecordAdapter(Context context, int layoutId) {
        super(context, layoutId);
    }

    public CustomerXiaoFeiRecordAdapter(Context context, int layoutId,
                                        PullLoadMoreRecyclerView pullLoadMoreRecyclerView,
                                        DataStateListener dataStateListener, OptListener optListener) {
        super(context, layoutId, pullLoadMoreRecyclerView, dataStateListener);
        this.optListener = optListener;
    }

    @Override
    public void convert(ViewHolder holder, XiaoFeiRecordBean xiaoFeiRecord, final int position) {
        TextView tv_credentials = holder.getView(R.id.tv_credentials);
        LinearLayout linear_credentials = holder.getView(R.id.linear_credentials);
        TextView tv_date = holder.getView(R.id.tv_date);
        TextView tv_shop_name = holder.getView(R.id.tv_shop_name);
        LinearLayout linear_lay = holder.getView(R.id.linear_lay);
        if(xiaoFeiRecord.getExpenseDate()!=null && !xiaoFeiRecord.getExpenseDate().equals("null")){
            tv_date.setText(xiaoFeiRecord.getExpenseDate());
        }else {
            tv_date.setText("");
        }
        if(xiaoFeiRecord.getShopName()!=null && !xiaoFeiRecord.getShopName().equals("null")){
            tv_shop_name.setText(xiaoFeiRecord.getShopName());
        }else {
            tv_shop_name.setText("");
        }

        //1：购买；
        //2：消耗；
        //3：退款；
        //4：余额购买
        int orderType = xiaoFeiRecord.getOrderType();
        if(orderType == 2){
            tv_credentials.setVisibility(View.VISIBLE);
        }else {
            tv_credentials.setVisibility(View.GONE);
        }

        List<XiaoFeiRecordItemBean> xiaoFeiRecordItemList = xiaoFeiRecord.getCommodityList();
        if(xiaoFeiRecordItemList!=null && xiaoFeiRecordItemList.size()>0){
            CustomerXiaoFeiRecordItemAdapter customerXiaoFeiRecordItemAdapter = new CustomerXiaoFeiRecordItemAdapter(
                    context,xiaoFeiRecordItemList,
                    R.layout.fragment_xiaofei_record_item_leaf,this,position,orderType);
            RecyclerView recyclerView = holder.getView(R.id.recycler);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            recyclerView.setLayoutManager(linearLayoutManager);
            recyclerView.setAdapter(customerXiaoFeiRecordItemAdapter);
        }

        linear_credentials.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
        linear_lay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
    }

    @Override
    public void onOptClick(View view, Object object) {
        int flag = (int) object;
        switch (view.getId()) {
            case R.id.linear_lay3:
                optListener.onOptClick(view,flag);
                break;
        }
    }
}
